Why StringWriter.ToString return `System.Byte[]` and not the data?

Posted by theateist on Stack Overflow See other posts from Stack Overflow or by theateist
Published on 2012-09-10T15:12:03Z Indexed on 2012/09/10 15:38 UTC
Read the original article Hit count: 142

Filed under:
|
|

UnZipFile method writes the data from inputStream to outputWriter. Why sr.ToString() returns System.Byte[] and not the data?

using (var sr = new StringWriter())
{
    UnZipFile(response.GetResponseStream(), sr);
    var content = sr.ToString();
}


public static void UnZipFile(Stream inputStream, TextWriter outputWriter)
{
    using (var zipStream = new ZipInputStream(inputStream))
    {
        ZipEntry currentEntry;
        if ((currentEntry = zipStream.GetNextEntry()) != null)
        {
            var size = 2048;
            var data = new byte[size];
            while (true)
            {
                size = zipStream.Read(data, 0, size);
                if (size > 0)
                {
                    outputWriter.Write(data);                       
                }
                else
                {
                    break;
                }
            }
        }
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about stream